class Solution {
public:
    vector<int> partitionLabels(string s) {
        vector<int> hash(26);
        int n = s.size();
        for(int i = 0; i < n; ++i)
        {
            hash[s[i] - 'a'] = i; // 记录每个元素出现的最远下标
        }

        vector<int> ret;
        int left = 0, right = 0;
        for(int i = 0; i < n; ++i)
        {
            right = max(right, hash[s[i] - 'a']);
            if(i == right)
            {
                ret.push_back(right - left + 1);
                left = right + 1;
            }
        }
        return ret;
    }
};